import uuid

from sqlalchemy import (
    Column,
    String,
    Integer,
    DateTime,
    PrimaryKeyConstraint,
    Boolean,
    text, Index
)
from internal.model.travel_agency import TravelAgency
from internal.model.tour_guide import TourGuide

from internal.entitry.tickets_entitry import TicketsStstaus
from internal.extension.extension_db import db
class Member(db.Model):
    __tablename__ = 'member'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='member_id_pkey'),
    )
    id = Column(String(36), nullable=False, default=lambda: str(uuid.uuid4()))
    playDate = Column(String(100), nullable=False) #预约日期
    grounp_id = Column(String(36), nullable=False,default="") #分组编号
    bash_id = Column(String(36), nullable=False)
    travel_agency_id = Column(String(36), nullable=False,default="")
    start_time = Column(String(100), nullable=True) #预约开始时间
    end_time = Column(String(100), nullable=True) #预约结束时间
    status = Column(String(20), nullable=False, default=TicketsStstaus.PADDING.value)  # 0初始状态，1预约成功，2提交成功，-1失败
    get_number = Column(Integer, nullable=True) #选择的安检口
    updated_at = Column(
        DateTime,
        nullable=False,
        server_default=text("CURRENT_TIMESTAMP(0)"),
        server_onupdate=text("CURRENT_TIMESTAMP(0)"),
    )
    created_at = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP(0)"))

    @property
    def get_agency(self)->'TravelAgency':
        return db.session.query(TravelAgency).filter(TravelAgency.id == self.travel_agency_id).one_or_none()
    @property
    def get_guide(self)->'TourGuide':
        return db.session.query(TourGuide).filter(TourGuide.bash_id == self.bash_id).one_or_none()